#!/bin/sh -euf

set -euf

BASE="$(dirname $0)"

if [ $# -ne 1 ]; then
	echo "usage: git-version-get fallback-file" >&2
	exit 2
fi

generate() {
	if [ -e $BASE/../.git ]; then
        cd $BASE/..
		git describe | sed 's/-[0-9]\+-g.*/.x/'
	else
		cat $1
	fi
}

# Omit the trailing new line, so this can be used directly
generate $1 | tr -d "\n\r"
